<?php if (!defined('THINK_PATH')) exit();?><html lang="en">
<head>
    <meta charset="UTF-8">
    <title><?php echo ($caption); ?></title>
    <link rel="stylesheet" href="/Public/User/pc/css/bootstrap.min.css">
    <link rel="stylesheet" href="/Public/User/css/swiper.min.css">
    <link rel="stylesheet" href="/Public/User/css/ion.calendar.css">
    <link rel="stylesheet" href="/Public/User/css/mystyle.css"/>
    <link rel="stylesheet" href="/Public/User/css/zTreeStyle.css">
    <link rel="stylesheet" href="/Public/User/css/treeDemo.css" type="text/css">
    <!--文件上传-->
    <link rel="stylesheet" href="/Public/User/css/jquery.filer.css">
    <link rel="stylesheet" href="/Public/User/css/jquery.filer-dragdropbox-theme.css">
    <link rel="stylesheet" href="/Public/User/css/custom.css">

    <script src="/Public/User/newjs/jquery.js"></script>
    <script src="/Public/User/js/swiper.min.js"></script>
    <script src="<?php echo $dic;?>"></script>
    <script src="<?php echo $layer;?>"></script>
    <script src="/Public/User/newjs/moment.min.js"></script>
    <script src="/Public/User/newjs/moment.zh-cn.js"></script>
    <script src="/Public/User/newjs/pc_dom_tool_final.js"></script>
    <script src="/Public/User/js/layer.js"></script>
    <script src="/Public/User/newjs/jquery.ztree.core.js"></script>
    <script src="/Public/User/newjs/myztree.js"></script>
    <!--文件上传插件-->
    <script src="/Public/User/newjs/jquery.filer.min.js" type="text/javascript"></script>
    <style>
        .swiper-container{
            overflow: visible !important;
        }
        .swiper-pagination{
            position: relative !important;
            top:9px !important;
            z-index: 999 !important
        }
        .swiper-pagination-bullet{
            margin-top:5px !important;
            width:20px;
            height:20px;
            text-align:center;
            line-height:20px;
            font-size:12px;
            color:#000;
            opacity:1;
            background:rgba(0,0,0,0.2);
        }
        .swiper-pagination-bullet-active{
            color:#fff;
            background:#007aff;
        }
    </style>
    <script>
        var menu = '<?php echo ($menu); ?>';  //子集名称
        var uuid = '<?php echo ($uuid); ?>';  //员工编码
        var sj_info = eval(<?php echo ($sj_info); ?>); //时间验证配置
        $(function () {
            //检测表单提交数据合法性
            var json = eval(<?php echo ($info); ?>);  //子集数据
            var kz_json = eval(<?php echo ($kz_info); ?>);  //扩展配置数据
            //console.log(layer_js);return;
            var change_item = '<?php echo ($change_item); ?>'; //已在审核中的子集
            var data = {
                name: menu,
                action: '/Pc/Info/edit',
                method: 'post',
                json: json.sublist,
                dic: dic,
                layer_js: layer_js,
                kz_json: kz_json,
                change_item: change_item,
                sp_type:json.sp_type,
                reason:json.reason
            };
            formStart(data);

            //检测表单提交数据合法性
            $('.btn-default').click(function (){
                //检测照片的大小和类型
                var obj = document.getElementById('inputFile_30');
                var zpresolt = fileZpSize(obj);
                if(!zpresolt){
                    return false;
                }
                //检测附件的大小和类型
                var tob = 0;
                $('.file_input').each(function(){
                    var fjresolt = fileFJSize($(this)[0]);
                    if(!fjresolt){
                        tob++;
                    }
                });
                if(tob){
                    return false;
                }

                //验证时间规则
                for(var i in sj_info){
                    var bj_val = $('input[name='+i+']').val();
                    var bj_name = $('input[name='+i+']').parent().parent().parent().find('label').text();
                    if(bj_name.indexOf('*')>-1){
                        bj_name = bj_name.substr(0, bj_name.length - 1);
                    }
                    var b_bj_val = $('input[name='+sj_info[i].max+']').val();
                    var b_bj_name = $('input[name='+sj_info[i].max+']').parent().parent().parent().find('label').text();
                    if(b_bj_name.indexOf('*')>-1){
                        b_bj_name = b_bj_name.substr(0, b_bj_name.length - 1);
                    }
                    if(sj_info[i].method == 1){
                        if(bj_val && b_bj_val && bj_val <= b_bj_val){
                            layer.alert(bj_name+' 不能小于或等于 '+b_bj_name);
                            return false;
                        }
                    }else if(sj_info[i].method == 2){
                        if(bj_val && b_bj_val && bj_val < b_bj_val){
                            layer.alert(bj_name+' 不能小于 '+b_bj_name);
                            return false;
                        }
                    }
                }
            });

            //唯一性验证
            $('.checkWyx').change(function () {
                var self = $(this);
                var val = $(this).val();
                var zd_name = $(this).attr('name');
                var form = $(this).parents('form');
                if (val == '是') {
                    var caption = $(this).parent().parent().parent().find('label').text();
                    caption = caption.substr(0, caption.length - 1);
                    var offset = form.find('input[name=_offset_id]').val();
                    var data = {uuid: uuid, item: menu, name: zd_name, offset: offset};
                    var resolot = aa(data);

                    if (resolot.type == 2) {
                        var text = '字段 ' + caption + ' 已经存在唯一值,您是保留当前值,更改其他该字段的值,还是更改当前字段的值该为否,其他记录值不变?';
                        layer.confirm(text, {
                            btn: ['保留', '不保留'] //按钮
                        }, function () {
                            var zj_input = '<input type="hidden" name="upd-' + zd_name + '" value="'+resolot.key+'">';
                            form.append(zj_input);
                            layer.msg(caption + '的值为是,将更改其他记录值!');
                        }, function () {
                            self.val('否');
                            layer.msg(caption + '的值改为否,其他记录此字段值不变!');
                        });
                    }
                }

            });
            function aa(data) {
                var resolt = null;
                $.ajax({
                    url: '/Pc/Info/checkWyx',
                    type: 'post',
                    data: data,
                    async: false,
                    success: function (e) {
                        resolt = e;
                    }
                });
                return resolt;
            }
            //已在审核的子集不能输入
            if(change_item.indexOf(menu) > -1){
                $('input').attr('disabled',true);
                $('select').attr('disabled',true);
                //附件不能点击删除和上传
                $('.removefile').hide();
                $('.clonebtn').html('　');

            }

            //监听返回首页按钮 返回上一页
            $('.callback_button').bind('click', function () {
                location.href = "/Pc/Pc/index";
            });

            //时间日期插件
            $('.date').each(function () {
                $(this).ionDatePicker({
                    lang: 'zh-cn',
                    format: 'YYYY-MM-DD',
                    years: '100'
                });
            });
            //初始化树形结
            for(var i in layer_id){
                $("#"+i).on("click",{i: i},function (e) {
                    var q=0;
                    $.fn.zTree.init($("#tree"), setting,layer_js[layer_id[e.data.i]]);
                    showMenu($(this));
                });
            }
            //重新调整树形结构宽度
            $(window).resize(function () {
                $("#menuContent").hide();
                $("#menuContent ul").width($("#inputText_0").parent('div').width()+"px");
            });
            $("#menuContent ul").width($("#inputText_0").parent('div').width()+"px");
        });

        /****************** 附件上传*******************************/
        //克隆上传文件按钮
        function add_file(e){
            var pNode=$(e).parents('.file_warp');
            pNode.parent('div').append(pNode.clone().children('input').val('').end()).children('.file_warp').eq(0).siblings().find('.file_add').attr("class",'file_remove').find('a').attr("onclick",'remove_file(this)').html("[-]");
        }
        //删除文件上传按钮
        function remove_file(e) {
            $(e).parents('.file_warp').remove();
        }
        //删除文件
        function  remove_result(e) {
            var self = $(e);
            var filename = $(e).attr('filename');
            var offset = $(e).attr('offset');
            var zd_name = $(e).attr('zd_name');
            layer.confirm('确定要删除此附件吗?',{
                btn : ['确定','取消']
            },function(){
                $.ajax({
                    url : '/Pc/Common/removeFile',
                    type : 'post',
                    data : {uuid:uuid,menu:menu,offset:offset,zd_name:zd_name,filename:filename},
                    async : false,
                    success : function(a){
                        if(a){
                            self.parents('.file_info').remove();
                            layer.msg('删除文件成功!');
                        }else{
                            layer.msg('删除文件失败!');
                        }
                    }
                });
            },function(){});

        }
        /*******************************************检测照片和附件的大小和类型*************************************************/
        //检测照片
        function fileZpSize(obj){
            if(!obj.value){
                return true;
            }
            var photoExt = obj.value.substr(obj.value.lastIndexOf(".")).toLowerCase();//获得文件后缀名
            var filetype = '.jpg,.gif,.png,.jpeg';
            //alert(filetype.indexOf(photoExt));return false;
            if(filetype.indexOf(photoExt)<0){
                layer.alert("上传的照片只支持jpg,gif,png,jpeg的格式!");
                return false;
            }
            var fileSize = 0;
            var isIE = /msie/i.test(navigator.userAgent) && !window.opera;
            if (isIE && !obj.files) {
                var filePath = obj.value;
                var fileSystem = new ActiveXObject("Scripting.FileSystemObject");
                var file = fileSystem.GetFile (filePath);
                fileSize = file.Size;
            }else {
                fileSize = obj.files[0].size;
            }
            fileSize=Math.round(fileSize/1024*100)/100; //单位为KB
            if(fileSize >= 2000){
                layer.alert("上传照片最大尺寸为2M，请重新上传!");
                return false;
            }
            return true;
        }
        //检测附件
        function fileFJSize(obj,tob){
            if(!obj.value){
                return true;
            }
            var photoExt = obj.value.substr(obj.value.lastIndexOf(".")).toLowerCase();//获得文件后缀名
            var filetype = '.jpg,.gif,.png,.jpeg,.xls,.xlsx,.doc,.docx,.ppt,.pptx';

            if(filetype.indexOf(photoExt)<0){
                tob++;
                layer.alert("上传的只支持'jpg', 'gif', 'png', 'jpeg','xls','xlsx','doc','docx','ppt','pptx'的格式!");
                return false;
            }
            var fileSize = 0;
            var isIE = /msie/i.test(navigator.userAgent) && !window.opera;
            if (isIE && !obj.files) {
                var filePath = obj.value;
                var fileSystem = new ActiveXObject("Scripting.FileSystemObject");
                var file = fileSystem.GetFile (filePath);
                fileSize = file.Size;
            }else {
                fileSize = obj.files[0].size;
            }
            fileSize=Math.round(fileSize/1024*100)/100; //单位为KB
            if(fileSize >= 2000){
                tob++;
                layer.alert("上传的附件大小超过2M，请重新上传!");
                return false;
            }
            return true;
        }
    </script>
</head>
<body>
<script src="/Public/User/newjs/ion.calendar.js"></script>
<div>
    <div class="content_wrap">
    </div>
    <div id="menuContent" class="menuContent" style=" display:none;position: absolute;">
        <ul id="tree" class="ztree" style="margin-top:0; width:370px; height: 300px;"></ul>
    </div>
    <div id="up_content" class="up_area">
        <div  class="btn-up_img">照片</div>
        <div class="img_wrap">
            <?php if($zp_img){ ?>
                <img id="ygpic" src="<?php echo $zp_img; ?>" alt="">
            <?php }else{ ?>
                <img id="ygpic" src="/Public/User/uploads/images/default.jpg" alt="">
            <?php } ?>
        </div>
    </div>
    <script src="/Public/User/newjs/custom.js" type="text/javascript"></script>
</div>
</body>
</html>